<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <table>
        <tr hidden>
            <td><label for="">id：</label></td>
            <td><input type="text" name="id"></td>
        </tr>
        <tr>
            <td><label for="">商品名称：</label></td>
            <td><input type="text" name="name"></td>
        </tr>
        <tr>
            <td><label for="">价格：</label></td>
            <td><input type="text" name="price"></td>
        </tr>
        <tr>
            <td><label for="">库存数量：</label></td>
            <td><input type="text" name="stock"></td>
        </tr>
        <tr>
            <td><label for="">供应商：</label></td>
            <td><input type="text" name="supplier"></td>
        </tr>
        <tr>
            <td><input type="button" value="保存" onclick="save()"></td>
            <td><input type="button" value="取消" onclick="cancel()"></td>
        </tr>
    </table>
    <script src="./js/jquery-3.6.0.min.js"></script>
    <script src="./js/init.js"></script>
    <script>
        let url = location.href
        let id = url.split('?')[1]
        console.log(id);
        $.get(`http://localhost:8080/product`,data=>{
            let newId = data.filter(item=>{
                return item.id == id
            })
            $('[name=id]').val(newId[0].id)
            $('[name=name]').val(newId[0].name)
            $('[name=price]').val(newId[0].price)
            $('[name=stock]').val(newId[0].stock)
            $('[name=supplier]').val(newId[0].supplier)
        })
    </script>
</body>
</html>